<%@ page import="pojo.Score" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: 21131
  Date: 2023/11/21
  Time: 14:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>教师查看考试成绩</title>
    <style>
        table {
            width: 1000px;
            margin-left: 20%;
            margin-top: 20px;
            text-align: center;
        }

        /*每个单元格*/
        th, td {
            border: 1px solid #999;
            text-align: center;
            padding: 20px 0;
            height: 40px;
        }

        /*偶数的tr的颜色*/
        table tr:nth-child(odd) {
            background-color: rgba(11, 114, 193, 0.45);
        }

        /*鼠标滑过的颜色*/
        table tr:hover {
            background-color: rgba(11, 114, 193, 0.15);
        }

        /*表格内的按钮*/
        button {
            height: 38px;
            width: 90px;
            background-color: white;
        }

        /*表头*/
        #mytable th {
            text-align: center;
        }

        /*搜索框*/
        .content_input .my-search {
            margin-left: 10px;
            margin-top: 20px;
            float: left;
            width: 30%;
            height: 38px;
            border-radius: 5px;
            color: dimgray;
        }

        .content_input .search_btn { /*按钮样式*/
            width: 80px;
            height: 40px;
            margin-top: 20px;
            margin-left: 30px;
            background-color: #428bca;
        }

        .content_input .search_btn:hover { /*按钮覆盖样式*/
            background-color: #2e6da4;
            color: ivory;
        }

        /*查看按钮*/
        .chakan {
            background-color: #78afe9;
            border: 2px solid black;
            height: 38px;
            width: 90px;
        }

        /*查看按钮悬浮颜色*/
        .chakan:hover {
            background-color: rgba(11, 114, 193, 0.15) ;
        }
    </style>
</head>
<body>
<jsp:include page="teacher_menu.jsp"></jsp:include>
<%--查询框--%>
<div style="background-color:  #78afe9;display: inline-block;margin-top: 10px;float: left;margin-left: 20%;height: 80px;width: 200px;text-align: center; border-radius:0px;">
    <h1 style="color:white;text-shadow: 2px 2px 2px dodgerblue;line-height: 40px;border-radius:2px;font-size: 25px">
        查看课程成绩</h1>
</div>
<div style="margin-left: 35%;margin-top:10px;width: 60%;height:80px;background-color: #78afe9; ">
    <form style="padding-left: 10%" action="${pageContext.request.contextPath }/search_Teacherscore" method="POST">
        <div class="content_input">
            <%--      查询按钮--%>
            <input class="my-search" type="text" placeholder="请输入考试名称" name="p_name">
            <input type="submit" class="btn btn-primary search_btn" value="查询">
            <%--      所有按钮--%>
            <form style="padding-left: 10%" action="${pageContext.request.contextPath }/loadScoreList" method="POST">
                <input type="submit" value="所有" class="btn btn-primary search_btn">
            </form>
        </div>
    </form>
</div>
<table id="mytable">
    <%--  表头--%>
    <tr style=" background-color: #78afe2;color: white;">
        <th>试卷名称</th>
        <th>平均成绩</th>
        <th>最高成绩</th>
        <th>试卷详情</th>
    </tr>
    <%--  表格内元素，所有试卷的成绩--%>
    <%
        List<Score> cs = (List<Score>) session.getAttribute("score");
        if (cs.isEmpty()) {//数据为空
    %>
    <tr>
        <td>数</td>
        <td>据</td>
        <td>为</td>
        <td>空</td>
    </tr>
    <%
        }
        for (Score c : cs) {
    %>
    <tr>
        <td><%=c.getPaper().getP_name()%>
        </td>
        <% if (c.getMax_score() >= 0) {//以防试卷已发布但是学生还未作答，成绩显示负数
        %>
        <td><%=c.getAvg_score()%>
        </td>
        <td><%=c.getMax_score()%>
        </td>
        <td>
            <input type="button" id="fa1" class="chakan" value="查看">
        </td>

        <%
        } else {%>
        <td>无
        </td>
        <td>无
        </td>
        <td>
            <input type="button"  class="chakan" style="font-size: 13px" value="暂时不能查看" disabled>
        </td>  <%}%>
        <%
            }
        %>
    </tr>
</table>
</body>
</html>
<script src="js/jquery-1.12.3.min.js"></script>
<script>
    // 获取点击查看的试卷名
    $(function () {
        $(".chakan").click(function () {
            var name1 = $(this).parents("tr").children("td:nth-child(1)").text();//获取点击发布对应的试卷名
            $.ajax({//传数据给controller判断是否已发布
                type: "post",
                url: "${pageContext.request.contextPath }/LoadListScore",
                data: {
                    "name": name1
                },
                async: true,
                success: function (data) {
                    console.log(data);//在控制台输出信息。
                    if(data==true){
                        window.location.replace("${pageContext.request.contextPath }/loadMyStudentsScoreList");
                    }
                }
            });

        })
    })
</script>